package hao.bk.royalmap;

import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * Một button trên header haoDV
 */
public class HeaderButton extends LinearLayout {

	private RoyalMapActivity main;

	private ExtendedTextView text;

	private ImageView icon;

	public HeaderButton(Context context, AttributeSet attrs) {
		super(context, attrs);
		main = (RoyalMapActivity) context;
		inflate(context, R.layout.header_button, this);
		text = (ExtendedTextView) findViewById(R.id.header_button_text);
		icon = (ImageView) findViewById(R.id.header_button_icon);
		setHeaderFocus(false);
	}

	/**
	 * Thay đổi màu chữ khi focus và không focus
	 */
	public void setHeaderFocus(boolean isFocus) {
		changeColorHeader(isFocus);
		if (isFocus) {
			//text.setTextColor(main.getResources().getColor(R.color.gray_dark));
			text.setTextColor(main.getResources().getColor(
					R.color.header_text_focus));
		} else {
			text.setTextColor(main.getResources().getColor(
					R.color.header_text_color));
		}
		invalidate();
	}

	/**
	 * Đổi màu icon
	 */
	private void changeColorHeader(boolean isFocus) {
		switch (getId()) {
		case R.id.parking_tab_save_btn:
			if (isFocus) {
				setIconHeader(R.drawable.parking_save_local_focused);
			} else {
				setIconHeader(R.drawable.parking_save_local);
			}
			break;
		case R.id.parking_tab_camera_btn:
			if (isFocus) {
				setIconHeader(R.drawable.parking_map_local_focused);
			} else {
				setIconHeader(R.drawable.parking_map_local);
			}
			break;
		case R.id.searchmap_from_local_btn:
			if(isFocus) {
				setIconHeader(R.drawable.parking_save_local_focused);
			} else {
				setIconHeader(R.drawable.parking_save_local);
			}
			break;
		case R.id.searchmap_to_local_btn:
			if(isFocus) {
				setIconHeader(R.drawable.searchmap_to_local_focused);
			} else {
				setIconHeader(R.drawable.searchmap_to_local);
			}
			break;
		case R.id.searchmap_favorite_local_btn:
			if(isFocus) {
				setIconHeader(R.drawable.searchmap_favorite_local_focused);
			} else {
				setIconHeader(R.drawable.searchmap_favorite_local);
			}
			break;
		}
	}

	public void setTextHeader(String textValue) {
		text.setText(textValue);
	}

	public void setIconHeader(int iconId) {
		icon.setImageDrawable(main.getResources().getDrawable(iconId));
	}

}
